package com.elontian.client;

import java.util.Map;

import android.widget.ImageView;

import com.elontian.http.async2.AsyncHttpFactory;
import com.elontian.http.async2.IAsyncHttpRequest;
import com.elontian.http.async2.handler.AsyncHttpHandler;
import com.elontian.http.sync.ISyncHttpRequest;
import com.elontian.http.sync.SyncHttpFactory;

/**
 * 
 * 网路异步加载数据类
 * 
 * 
 * 
 * @author 胡松振
 * 
 */

public class HttpRequestClient {
	private static final IAsyncHttpRequest iar = AsyncHttpFactory
			.createAsyncHttpRequest();
	private final static ISyncHttpRequest ishr = SyncHttpFactory
			.createHttpRequest();

	/**
	 * get
	 * 
	 * @param url
	 *            请求url
	 * @param handler
	 *            回调接口
	 */

	public static void AsyncGet(String url, AsyncHttpHandler handler) {
		iar.get(url, handler);
	}

	/**
	 * post
	 * 
	 * @param url
	 *            请求url
	 * @param params
	 *            请求参数
	 * @param handler
	 *            回调接口
	 */
	public static void AsyncPost(String url, Map<String, Object> params,
			AsyncHttpHandler handler) {
		iar.post(url, params, handler);
	}

	public static String SyncGet(String url) {
		String result = null;
		try {
			result = ishr.get(url);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public static String SyncPost(String url, Map<String, Object> params) {
		String result = null;
		try {
			result = ishr.post(url, params);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}
}
